CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(FOSolverS)
ENABLE_LANGUAGE(Fortran C)

# compiler & linker arguments
SET(CMAKE_Fortran_COMPILER mpif90)
SET(CMAKE_Fortran_FLAGS "-Wall -Ofast -march=native -fopenmp")
SET(CMAKE_C_COMPILER mpicc)
SET(CMAKE_C_FLAGS "-Wall -Ofast -march=native -fopenmp -std=c11")
SET(CMAKE_EXE_LINKER_FLAGS "-Wall -Ofast -march=native -fopenmp")
SET(CMAKE_SHARED_LINKER_FLAGS "-Wall -Ofast -march=native -fopenmp")

# module, executable & lib output directories
SET(CMAKE_Fortran_MODULE_DIRECTORY ${PROJECT_BINARY_DIR}/include)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

# include/library directories
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR}/include)
LINK_DIRECTORIES(${PROJECT_BINARY_DIR}/lib)

# external packages
# CGNS
FIND_PATH(CGNS_INCLUDE_DIR cgnslib_f.h)
IF(CGNS_INCLUDE_DIR)
  INCLUDE_DIRECTORIES(${CGNS_INCLUDE_DIR})
  MESSAGE(STATUS "Found CGNS.")
ELSE(CGNS_INCLUDE_DIR)
  MESSAGE(SEND_ERROR "Unable to find CGNS.")
ENDIF(CGNS_INCLUDE_DIR)
# hdf5
FIND_PACKAGE(HDF5)
IF(HDF5_LIBRARIES)
  INCLUDE_DIRECTORIES(${HDF5_INCLUDE_DIR})
ENDIF(HDF5_LIBRARIES)
# BLAS
FIND_LIBRARY(BLAS_LIBRARY blas)
IF(BLAS_LIBRARY)
  MESSAGE(STATUS "Found BLAS.")
ELSE(BLAS_LIBRARY)
  MESSAGE(SEND_ERROR "Unable to find BLAS.")
ENDIF(BLAS_LIBRARY)
# LAPACK
FIND_LIBRARY(LAPACK_LIBRARY lapack)
IF(LAPACK_LIBRARY)
  MESSAGE(STATUS "Found LAPACK.")
ELSE(LAPACK_LIBRARY)
  MESSAGE(SEND_ERROR "Unable to find LAPACK.")
ENDIF(LAPACK_LIBRARY)
# SUNDIALS
FIND_LIBRARY(CVODE_LIBRARY1 sundials_fcvode)
FIND_LIBRARY(CVODE_LIBRARY2 sundials_fnvecserial)
FIND_LIBRARY(CVODE_LIBRARY3 sundials_cvode)
FIND_LIBRARY(CVODE_LIBRARY4 sundials_nvecserial)
SET(CVODE_LIBRARIES ${CVODE_LIBRARY1} ${CVODE_LIBRARY2} ${CVODE_LIBRARY3} ${CVODE_LIBRARY4})
IF(CVODE_LIBRARIES)
  MESSAGE(STATUS "Found CVODE.")
ELSE(CVODE_LIBRARIES)
  MESSAGE(SEND_ERROR "Unable to find CVODE.")
ENDIF(CVODE_LIBRARIES)
# matheval
FIND_LIBRARY(MATHEVAL_LIBRARY matheval)
IF(MATHEVAL_LIBRARY)
  MESSAGE(STATUS "Found libmatheval.")
ELSE(MATHEVAL_LIBRARY)
  MESSAGE(SEND_ERROR "Unable to find libmatheval.")
ENDIF(MATHEVAL_LIBRARY)

# subdirectories
ADD_SUBDIRECTORY(src)
